package com.lonelymeko.shishou.service;

import com.lonelymeko.summer.BeanPostProcessor;
import com.lonelymeko.summer.Component;
import java.lang.reflect.Proxy;
import java.util.Arrays;

@Component
public class ShishouBeanPostProcessor implements BeanPostProcessor {


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        System.out.println("初始化前后置处理方法");
        if(beanName.equals("userService")){
            //创建jdk动态代理
            System.out.println(Arrays.toString(bean.getClass().getInterfaces()));
            Object proxyInstance = Proxy.newProxyInstance(ShishouBeanPostProcessor.class.getClassLoader(), bean.getClass().getInterfaces(),
                    (proxy, method, args) -> {
                        System.out.println("userService后置切面方法");
                        return method.invoke(bean, args);
                    });
            return proxyInstance;


        }
        return bean;
    }
}

